﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HotelProject.Account
{
    public partial class Register : System.Web.UI.Page
    {
        private MySQLDatabaseConnector database;

        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
            database = new MySQLDatabaseConnector();
        }

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            //FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

            /*string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                continueUrl = "~/";
            }*/
            
            //Response.Redirect(continueUrl);
            
            AddUser();
        }

        
        protected void AddUser()
        {
            //stores registered username and password into local varables 
            string username = RegisterUser.UserName;
            string password = RegisterUser.Password;
            

            //creats a user to be registered
            registeredUser userToAdd = new registeredUser() {userFirstName ="Adam", userLastName="Cole", userName = "adamC", isAdmin=false, userPassword="money5"};
            
           

            //adds the user to database
            database.addUser(userToAdd);
            
            Save();
        }

        protected void Save()
        {
            database.saveChanges();
        }
        

    }
}
